/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package almacenamiento;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

/**
 *
 * @author Usuario
 */
public class leerTuplasTarea {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        
        List<Atributo> attrs = new ArrayList<Atributo>();
            attrs.add(new Atributo("character", Character.class));
            attrs.add(new Atributo("byte", Byte.class));
            attrs.add(new Atributo("short", Short.class));
            attrs.add(new Atributo("integer", Integer.class));
            attrs.add(new Atributo("long", Long.class));
            attrs.add(new Atributo("float", Float.class));
            attrs.add(new Atributo("double", Double.class));
            attrs.add(new Atributo("string", String.class));
            Relacion rel = new Relacion(attrs);
            
          // List<Comparable> v = new ArrayList<Comparable>();
//            v.add(new Character('a'));
//            v.add(new Byte((byte) 26));
//            v.add(new Short((short) 312));
//            v.add(new Integer(2048));
//            v.add(new Long(34567));
//            v.add(new Float(12.3));
//            v.add(new Double(25.6));
//            v.add(new String("bla bla"));
            System.out.print("NUMERO DE TUPLAS : ");
            int nroTuplas = in.nextInt();
            
            //List<Comparable> lista = new ArrayList<Comparable>();
            
            List<GestorIOTupla> listas = new ArrayList<GestorIOTupla>();
            List<Tupla> listaTupla = new ArrayList<Tupla>();
             
            for (int i = 0; i < nroTuplas; i++) 
            {   
                List<Comparable> v = new ArrayList<Comparable>();
                System.out.print("char: "); 
                char a = in.next().toCharArray()[0];
                v.add(new Character(a));
                System.out.print("byte: "); 
                v.add(new Byte(in.nextByte()));
                System.out.print("short: "); 
                v.add(new Short(in.nextShort()));
                System.out.print("integer: "); 
                v.add(new Integer(in.nextInt()));
                System.out.print("long: "); 
                v.add(new Long(in.nextLong()));
                System.out.print("float: ");
                String flotante = in.next();
                float numeroflotante = Float.parseFloat (flotante);
                v.add(new Float(numeroflotante));
                System.out.print("double: "); 
                String doble = in.next();
                double numerodoble = Double.parseDouble(doble);
                v.add(new Double(numerodoble));
                System.out.print("string : "); 
                v.add(new String(in.next().toString())); 
                
                Tupla t = new Tupla(new IdentificadorTupla("redes"+i, i), v);
                GestorIOTupla man = new GestorIOTupla(rel, "redes"+i);
 
                listaTupla.add(t);
                listas.add(man);
  
            }
            for (int j = 0; j < nroTuplas; j++) {
                Tupla t = listaTupla.get(j);
                System.out.println("writing tuple..." + t);
                byte[] bytes = new byte[1024];
                GestorIOTupla a  = listas.get(j);
                a.escribirTupla(t, bytes, j);
                
                System.out.println("Mostrar le arreglo de bytes: "+bytes);
                
                System.out.println("reading tuple...");
                // t = man.leerTupla(bytes);
                Par<Tupla, Integer> st = a.leerTupla(bytes, j);
                System.out.println(st);
                System.out.println("...............................................");
                System.out.println();  
                
            }
        }
}
